package Bean;

import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TextField;

import java.io.Serializable;
import java.util.ArrayList;

public class MindMapNode extends TextField implements Serializable {

    private  transient SimpleStringProperty text = new SimpleStringProperty();

    private  transient SimpleDoubleProperty x = new SimpleDoubleProperty();

    private  transient SimpleDoubleProperty y = new SimpleDoubleProperty();

    private String Mtext;

    private double Mx;

    private double My;

    private boolean isCenter = false;

    private  int deep;

    private int high;

    private boolean left;

    private ArrayList<MindMapNode> childNode = new ArrayList<MindMapNode>();

    private MindMapNode parentNode;

    public MindMapNode(){}

    public MindMapNode(String text){
        init(text);
    }

    public void init(String text){
        super.setText(text);
        this.text.set(text);
        super.textProperty().bindBidirectional(this.text);
        super.layoutXProperty().bindBidirectional(this.x);
        super.layoutYProperty().bindBidirectional(this.y);
    }

    public ArrayList<MindMapNode> getChildNode() {
        return childNode;
    }

    public void setChildNode(ArrayList<MindMapNode> childNode) {
        childNode = childNode;
    }

    public String getTextProperty() {
        return text.get();
    }


    public void setTextProperty(String text) {
        if(this.text==null){
            this.text = new SimpleStringProperty();
        }
        this.text.set(text);
    }

    public double getX() {
        return x.get();
    }


    public void setX(double x) {
        if(this.x==null){
            this.x = new SimpleDoubleProperty();
        }
        this.x.set(x);
    }

    public double getY() {
        return y.get();
    }


    public void setY(double y) {
        if(this.y==null){
            this.y = new SimpleDoubleProperty();
        }
        this.y.set(y);
    }

    public String getMtext() {
        return Mtext;
    }

    public void setMtext(String mtext) {
        Mtext = mtext;
    }

    public double getMx() {
        return Mx;
    }

    public void setMx(double mx) {
        Mx = mx;
    }

    public double getMy() {
        return My;
    }

    public void setMy(double my) {
        My = my;
    }

    public boolean isCenter() {
        return isCenter;
    }

    public void setCenter(boolean center) {
        isCenter = center;
    }

    public SimpleDoubleProperty xProperty() {
        return x;
    }

    public SimpleDoubleProperty yProperty() {
        return y;
    }

    public SimpleStringProperty getTextOfProperty(){
        return text;
    }

    public MindMapNode getParentNode() {
        return parentNode;
    }

    public void setParentNode(MindMapNode parentNode) {
        this.parentNode = parentNode;
    }


    public int getDeep() {
        return deep;
    }

    public void setDeep(int deep) {
        this.deep = deep;
    }

    public void addDeep(int deep){
        this.deep += deep;
    }

    public int getHigh(){
        return high;
    }

    public void setHigh(int high){
        this.high = high;
    }

    public void addHigh(int high){
        this.high += high;
    }

    public void setLeft(boolean left) {
        this.left = left;
    }

    public boolean isLeft(){
        return left;
    }

    @Override
    public String toString() {
        return "MindMapNode{" +
                "text=" + text +
                ", high=" + high +
                ", childNode=" + childNode +
                ",left=" + left +
                '}';
    }
}
